package org.gap.service;

import java.util.List;
import java.util.Set;

import org.gap.domain.Relations;
import org.gap.domain.RelationsTiers;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/GAP_v2-security-context.xml",
		"file:./resources/GAP_v2-service-context.xml",
		"file:./resources/GAP_v2-dao-context.xml",
		"file:./resources/GAP_v2-web-context.xml" })
@Transactional
public class RelationsServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected RelationsService service;

	/**
	 * Instantiates a new RelationsServiceTest.
	 *
	 */
	public RelationsServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return all Relations entity
	 * 
	 */
	@Test
	public void findAllRelationss() {
		// TODO: JUnit - Populate test inputs for operation: findAllRelationss 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Relations> response = null;
		response = service.findAllRelationss(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllRelationss
	}

	/**
	 * Operation Unit Test
	 * Save an existing RelationsTiers entity
	 * 
	 */
	@Test
	public void saveRelationsRelationsTierses() {
		// TODO: JUnit - Populate test inputs for operation: saveRelationsRelationsTierses 
		String relRelation = null;
		RelationsTiers related_relationstierses = new org.gap.domain.RelationsTiers();
		Relations response = null;
		response = service.saveRelationsRelationsTierses(relRelation, related_relationstierses);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRelationsRelationsTierses
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findRelationsByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findRelationsByPrimaryKey 
		String relRelation_1 = null;
		Relations response = null;
		response = service.findRelationsByPrimaryKey(relRelation_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findRelationsByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Load an existing Relations entity
	 * 
	 */
	@Test
	public void loadRelationss() {
		Set<Relations> response = null;
		response = service.loadRelationss();
		// TODO: JUnit - Add assertions to test outputs of operation: loadRelationss
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Relations entity
	 * 
	 */
	@Test
	public void countRelationss() {
		Integer response = null;
		response = service.countRelationss();
		// TODO: JUnit - Add assertions to test outputs of operation: countRelationss
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Relations entity
	 * 
	 */
	@Test
	public void deleteRelations() {
		// TODO: JUnit - Populate test inputs for operation: deleteRelations 
		Relations relations = new org.gap.domain.Relations();
		service.deleteRelations(relations);
	}

	/**
	 * Operation Unit Test
	 * Save an existing Relations entity
	 * 
	 */
	@Test
	public void saveRelations() {
		// TODO: JUnit - Populate test inputs for operation: saveRelations 
		Relations relations_1 = new org.gap.domain.Relations();
		service.saveRelations(relations_1);
	}

	/**
	 * Operation Unit Test
	 * Delete an existing RelationsTiers entity
	 * 
	 */
	@Test
	public void deleteRelationsRelationsTierses() {
		// TODO: JUnit - Populate test inputs for operation: deleteRelationsRelationsTierses 
		String relations_relRelation = null;
		Integer related_relationstierses_rltTiersParent = 0;
		Integer related_relationstierses_rltTiersFils = 0;
		String related_relationstierses_rltRelation = null;
		Relations response = null;
		response = service.deleteRelationsRelationsTierses(relations_relRelation, related_relationstierses_rltTiersParent, related_relationstierses_rltTiersFils, related_relationstierses_rltRelation);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRelationsRelationsTierses
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
